Repository navigation
feat(pm-agg): C4.4 arrival prediction records — honesty-first emission, validation, scoring (#13260) - #13299
Conversation
…n, validation, scoring (#13260) New pure module pm-stack/aggregator/src/quota-arrival.ts implementing the model_plan_arrival kind of the C4 prediction record (design doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/ c4-forecasting-design.md §1/§3/§7): - buildArrivalRecords: one predicted record per named basis that can honestly bound a range — detector_history (the pool's S5 plan-change findings read as arrival instants; >=2 spread intervals bound the next arrival) and vendor_cadence (a cadence actually recorded, with a measured spread). One interval, identical intervals, or a spread-less recorded period are the insufficient_history honesty state; no evidence at all is the explicit no_basis state with every absence named. Bases are never blended. - validateArrivalRecord enforces the contract and the builder runs every emitted record through it: a predicted record must name a real basis and a strictly bounded range (a point date is refused); an honesty-state record must carry no range at all — a record without a basis is never published, so no speculative date can leave the module. - scoreArrivalPrediction: hit/miss plus lead time on hits (§3); honesty-state records are never scored and open predictions are unscored, never assumed. - renderPredictionRange: §4 duration/day forms, stored on the record. Tests (src/quota-arrival.test.ts, 20 tests) name the design record as their oracle. The live wiring (gatherer tick -> quota-predictions.jsonl + Turso mirror under source "quota-prediction") is a follow-up slice; #13260 stays open on it and on the §4 calendar rendering form.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 46 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e24f50b10
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| test("every builder-emitted record validates", () => { | ||
| for (const rec of buildArrivalRecords(baseInput)) expect(() => validateArrivalRecord(rec)).not.toThrow(); | ||
| expect(() => validateArrivalRecord(predicted())).not.toThrow(); |
There was a problem hiding this comment.
Cover arrival invariants with generated property tests
The new suite checks its claimed “every builder-emitted record validates” invariant against only two fixed fixtures, and contains no generated property/model coverage. The repository testing doctrine requires PBT where code has invariants and MBT where a specification exists; this module has both explicit range/state invariants and the cited C4 design. Add generated histories and cadences covering bounded predictions, honesty states, pool isolation, and duplicate/order invariance rather than relying exclusively on handwritten examples.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
| const earliest = last + minI; | ||
| const latest = last + maxI; |
There was a problem hiding this comment.
Stop emitting detector predictions after their window expires
When issuance occurs more than the longest measured interval after the last arrival, these bounds are entirely in the past, but the builder still publishes a validated predicted record. For example, arrivals on days 0, 10, and 25 issued on day 50 produce a day 35–40 prediction and a negative “days from now” rendering. Unchanged history will keep emitting this expired forecast at every subsequent issuance. Check the bounds against issuedMs and emit a named honesty state when the next-arrival window has already elapsed rather than publishing a retrospective prediction.
Useful? React with 👍 / 👎.
| const instants = arrivalInstants(input.detectorFindings, input.subject.pool); | ||
| if (instants.length >= 2) { | ||
| evidenceSeen = true; |
There was a problem hiding this comment.
Classify a single recorded arrival as insufficient history
With exactly one matching plan-change finding and no vendor cadence, this branch never sets evidenceSeen, so the final record is no_basis despite having detector-history evidence. This contradicts the builder's documented distinction between no evidence and evidence that cannot bound a range, and makes the first observed arrival indistinguishable from an empty history to state consumers. Mark evidence as present whenever at least one attributable arrival exists, while retaining the explanation that no interval is measurable.
Useful? React with 👍 / 👎.
| test("every builder-emitted record validates", () => { | ||
| for (const rec of buildArrivalRecords(baseInput)) expect(() => validateArrivalRecord(rec)).not.toThrow(); | ||
| expect(() => validateArrivalRecord(predicted())).not.toThrow(); |
There was a problem hiding this comment.
Cover arrival invariants with generated property tests
The claimed “every builder-emitted record validates” invariant is checked only against two fixed fixtures, and the rest of this new suite likewise contains only hand-written examples. The repository testing doctrine requires PBT where code has invariants and MBT where a specification exists; this module has both explicit range/state invariants and the cited C4 design. Add generated histories and cadences covering bounded predictions, honesty states, pool isolation, and duplicate/order invariance rather than relying exclusively on handwritten examples.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
| if (f.detector !== "plan-change") continue; | ||
| if (f.providerId !== pool) continue; |
There was a problem hiding this comment.
Resolve pool identity for limit-change findings before filtering
When supplied with S5 findings from quota-limit changes, this filter discards every arrival: observeLimitRecord in quota-anomaly.ts:661–680 always sets providerId: null, and both runAnomalyReplay and the live tick append those findings without enriching that identity. Consequently, even a pool with several measured limit changes produces no_basis unless its window kinds also changed; the tests conceal this by constructing limit-change findings with a populated provider ID. Resolve known service IDs through the existing FORECAST_POOLS service-to-provider mapping before filtering, or populate provider identity in the producer, while continuing to reject genuinely unattributable findings.
Useful? React with 👍 / 👎.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Part of #13260 (C4.4, component of #9572). One bounded slice: the
model_plan_arrivalrecord contract from the C4 design record (§1/§3/§7), as a pure module in the quota-anomaly.ts discipline.What lands —
pm-stack/aggregator/src/quota-arrival.ts:buildArrivalRecords— one predicted record per named basis that can honestly bound a range:detector_history(the pool's S5 plan-change findings read as arrival instants; ≥2 spread intervals bound the next arrival, median as likely) andvendor_cadence(a cadence actually recorded, with a measured spread; stale anchors roll forward). One interval, identical intervals, or a spread-less recorded period yield theinsufficient_historyhonesty state; no evidence at all yields the explicitno_basisstate with every absence named. Bases are never blended.validateArrivalRecord— enforces the contract; the builder runs every emitted record through it. A predicted record must name a real basis and a strictly bounded range (a point date is refused); an honesty-state record must carry no range at all. A record without a basis is never published — no speculative date can leave the module.scoreArrivalPrediction— hit/miss plus lead time on hits (§3); honesty-state records are never scored; open predictions are unscored, never assumed.renderPredictionRange— §4 duration/day forms, stored on the record at issuance.Tests —
src/quota-arrival.test.ts, 20 tests naming the design record as oracle: 20 pass;bunx tsc --noEmitclean; neighbouring quota suites (anomaly, forecast) green.Remainder for #13260 (issue stays open): the live wiring — gatherer tick emitting records to
quota-predictions.jsonlwith the Turso mirror under sourcequota-prediction(the constant is exported here for exactly one spelling) — first scored outcomes against live arrivals, and §4's calendar rendering form.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.